import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution1 {
    public static List<List<Integer>> ret = new ArrayList<>();
    public static List<Integer> path = new ArrayList<>();
    public static boolean[] check;

    public static void main(String[] args) {
        int[] nums = {3,3,0,3};
        Arrays.sort(nums);
        permuteUnique(nums);
        for(List<Integer> list : ret) {
            for(Integer i : list) {
                System.out.print(i + " ");
            }
            System.out.println();
        }



    }
    public static List<List<Integer>> permuteUnique(int[] nums) {
        check = new boolean[nums.length];
        dfs(nums);
        return ret;
    }

    public static void dfs(int[] nums) {
        if(path.size() == nums.length) {
            ret.add(new ArrayList<>(path));
            return;
        }

        for(int i = 0; i < nums.length; i++) {
            if(i > 0 && nums[i] == nums[i - 1] && check[i - 1] == false) //去重
                continue;
            if(check[i] == false) {
                path.add(nums[i]);
                check[i] = true;
                dfs(nums);
                path.remove(path.size() - 1);
                check[i] = false;
            }
        }
    }
}
